package com.demo.house.service.impl;

import com.demo.house.dao.AppointmentDao;
import com.demo.house.dao.HouseSourseDao;
import com.demo.house.dao.UserHouseDao;
import com.demo.house.entity.Appointment;
import com.demo.house.entity.HouseSourse;
import com.demo.house.entity.UserHouse;
import com.demo.house.service.UserHouseService;
import com.demo.house.vo.RequestVo.UserHouseRentVo;
import com.demo.house.vo.RequestVo.UserHouseVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserHouseServicelmpl implements UserHouseService {
    @Autowired
    private UserHouseDao userHouseDao;

    @Autowired
    private HouseSourseDao houseSourseDao;


    @Override
    public int updateByPrimaryKey(UserHouseVo userHouseVo) {
        UserHouse userHouse = new UserHouse();
        userHouse.setId(userHouseVo.getId());
        userHouse.setHouseSourseId(userHouseVo.getHouseSourseId());
        userHouse.setUserId(userHouseVo.getUserId());
        return userHouseDao.updateByPrimaryKey(userHouse);
    }

    @Override
    public List<UserHouse> selectHouseByuseId(Integer id) {
        List<UserHouse> userHouses = userHouseDao.selectHouseByuseId(id);
        System.out.println("111111111111" + userHouses);
        return userHouseDao.selectHouseByuseId(id);
    }

    @Override
    public int insertSelective(UserHouseRentVo userHouseRentVo) {
        int a=0;
        HouseSourse houseSourse2 = new HouseSourse();
        houseSourse2.setId(userHouseRentVo.getHouseSourseId());
        houseSourse2.setState(2);

        int i = userHouseDao.insertSelective(userHouseRentVo);
        if (i==1){
            int i1 = houseSourseDao.updateState(houseSourse2);
            a=i1;
            return a;
        }
        return userHouseRentVo.getId();
    }

    @Override
    public List<UserHouse> selectName(Integer id) {
        List<UserHouse> userHouses = userHouseDao.selectName(id);
        System.out.println("77777" + userHouses);
        return userHouseDao.selectName(id);
    }

}
